package org.ceteca.explica.core.partners;

import java.io.Serializable;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.ceteca.explica.core.common.BaseVO;



/**
 * @author Juan C. Díaz (juancarlosdiaz@ceteca.net) <br>
 *         Copyright (c) 2009 Fundación Centro Tecnolóxico da Carne
 * 
 * <br>
 * <br>
 *         This program is free software: you can redistribute it and/or modify
 *         it under the terms of the GNU General Public License as published by
 *         the Free Software Foundation, either version 3 of the License, or (at
 *         your option) any later version. <br/>
 *         This program is distributed in the hope that it will be useful, but
 *         WITHOUT ANY WARRANTY 
 *         <br>without even the implied warranty of
 *         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 *         General Public License for more details. <br/>
 *         You should have received a copy of the GNU General Public License
 *         along with this program. If not, see <http://www.gnu.org/licenses/>.
 * 
 */
public class DepartmentOT extends BaseVO implements Serializable {


	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/**
	 * 
	 */

	private long idDepartment;
	private String name;
	private Integer version=new Integer(0);
	
	
	
	
	
	public DepartmentOT() {
		super();
	}

	public long getIdDepartment() {
		return idDepartment;
	}

	public void setIdDepartment(long idDepartment) {
		this.idDepartment = idDepartment;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	
	
	
	
	
	public Integer getVersion() {
		return version;
	}


	
	@Override
	public boolean equals(Long id) {
		return id != null && this.idDepartment == id.longValue();
	}

	@Override
	public String getEntityId() {

		return InterfacePartners.EXPLICA_ENTITY_DEPARTMENT_ID;
	}

	@Override
	public long getInternalId() {

		return this.idDepartment;
	}

	@Override
	public String getInternalValue() {
		
		return this.name;
	}

	public void setVersion(Integer version) {
		this.version = version;
	}

	@Override
	public String toString() {

		StringBuffer result = new StringBuffer();
		
	try{
			result.append("\n%%%%%%%%%%%% BEGIN DEPARTMENT DETAIL %%%%%%%%%%%%%%");
			result.append("\nID: ");
			result.append(this.idDepartment);
			result.append("\nName: ");
			result.append(this.name);
			result.append("\n%%%%%%%%%%%% END  DEPARTMENT DETAIL%%%%%%%%%%%%%%%%");
		}
		catch (Exception ex) {
			System.out.println("Error formatting Departmen!");
			ex.printStackTrace();
			return null;
		}
		
		return result.toString();
	}



	   @Override
	    public int hashCode() {
	        final HashCodeBuilder hcb = new HashCodeBuilder();
	        hcb.append(getName());


	        return hcb.toHashCode();
	    }

	    
	    
	    @Override
	    public boolean equals(Object obj) {
	        boolean isEquals = false;
	        try {
	            final DepartmentOT other = (DepartmentOT)obj;
	            final EqualsBuilder eqb = new EqualsBuilder();
	            eqb.append(getName(), other.getName());
	            isEquals = eqb.isEquals();

	        } catch (Exception e) {
	            isEquals = false;
	        }

	        return isEquals;
	    }
	
	
	
	
}
